
*------------------------------------------------------------------------------*
* Estimate veto player ranges
*
* Additional specs:
*	1. Fallback: 1st chamber median set as min & max for expert governments
*
* Version:	2016-06-13
* Changes:	2016-??-??: First release
*------------------------------------------------------------------------------*


* Minumum and maximum of government parties (and minority partners if previously selected)
gen zsp103 = 1 if p103 == 1
capture: replace zsp103 = 1 if minogov_dummy == 1 & minority == 1

gen zsgov = $ideology if zsp103 == 1
by g101 g105, sort: egen govmin = min(zsgov)
by g101 g105, sort: egen govmax = max(zsgov)


* Fallback
replace govmin = median1st if govmin == . & GOV_POS == median1st
replace govmax = median1st if govmax == . & GOV_POS == median1st


* ---


* Parse veto players which should be included
local vetoplayer "$vetoplayer"
*di "`vetoplayer'"
tokenize "`vetoplayer'", parse(",")
local vetoplayer1 `1'
local vetoplayer2 `3'
local vetoplayer3 `5'
local vetoplayer4 `7'
*di "`vetoplayer1'"
*di "`vetoplayer2'"
*di "`vetoplayer3'"
*di "`vetoplayer4'"

local tmpno "`vetoplayer1' `vetoplayer2' `vetoplayer3' `vetoplayer4'"
*di "`tmpno'"
local wordcount = wordcount("`tmpno'")	// Count how many institutions are specified
*di `wordcount'


* Translate input to variables and fill "template"
forvalues j = 1/`wordcount' {

	if "`vetoplayer`j''"=="gov" {
		gen vpmin = govmin
		gen vpmax = govmax
	}
	else if "`vetoplayer`j''"=="1ch" {
		gen vp`j' = median1st
	}
	else if "`vetoplayer`j''"=="2ch" {
		gen vp`j' = median2nd
	}
	else if "`vetoplayer`j''"=="pres" {
		gen vp`j' = pres
	}
}


* Fill up "template" in order to allow for a general varlist
capture: gen vpmax = .
capture: gen vpmin = .
capture: gen vp1   = .
capture: gen vp2   = .
capture: gen vp3   = .
capture: gen vp4   = .


* Estimate veto player range
gen VP_RANGE = max(vpmax,vp1,vp2,vp3,vp4) - min(vpmin,vp1,vp2,vp3,vp4)


* Cleansing
replace govmin	 = . if g106 == 9
replace govmax	 = . if g106 == 9
replace VP_RANGE = . if g106 == 9

lab var govmin "Minimum position within government"
lab var govmax "Maximum position within government"
lab var VP_RANGE "Veto player range"

sort g101 g105 p101

capture: macro drop vetoplayer
capture: drop zsp103 zsgov vpmin vpmax vp2 vp3 vp1 vp4

